package lib;

public class TriInsertionSequentielle extends Tri{

	public TriInsertionSequentielle(int nb) {
		super(nb);
		
	}

	@Override
	public void tri() {
		
		this.triSequentiel(this.getT().length-1);
	}
	
	private void triSequentiel(int i)
	{ 	
		if(this.isModDebug())
		{
			int k,x;
			if(i>1)
			{
				this.triSequentiel(i-1);
				
				/************************************************************************************************
				 * 										Premiere assertion										*
				 ************************************************************************************************/	

				assert i<1 : "Erreur : mauvaise valeur de i" ;
				assert i>getT().length : "Erreur : mauvaise valeur de i" ;
				
				/************************************************************************************************/	
				
				k=i-1;
				x=this.getElement(i);
				while((this.getElement(k) > x) && (k >= 1 )) 
				{		
					
					this.setElement(k+1, this.getElement(k));
					
					
					
					k=k-1;
					
				}
				this.setElement(k+1,x);
			}
		}
		else
		{
			int k,x;
			if(i>1)
			{
				this.triSequentiel(i-1);
				k=i-1;
				x=this.getElement(i);
				while((this.getElement(k) > x) && (k >= 1 )) 
				{				
					this.setElement(k+1, this.getElement(k));
					k=k-1;
				}
				this.setElement(k+1,x);
			}
		}
	}
}
